package com.geostar.constructionland.analyse.service.handler.impl;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.geostar.constructionland.analyse.entity.HttpResult;
import com.geostar.constructionland.analyse.entity.alyresult.AlyResult;
import com.geostar.constructionland.analyse.entity.model.AnalyseModel;
import com.geostar.constructionland.analyse.entity.resulthandler.HandlerResult;
import com.geostar.constructionland.analyse.service.analyseresult.IStbhhxService;
import com.geostar.constructionland.analyse.service.handler.IResultHandler;
import com.geostar.constructionland.common.dao.YzGeoJsonDao;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/***
 * @Author makoto_zhu
 * @Date 2021-03-12 11:37:11
 * @Description
 **/
@Component
@Slf4j
public class MineCommonHandler implements IResultHandler {

    @Autowired
    ObjectMapper objectMapper;

    @Autowired
    IStbhhxService stbhhxService;

    @Override
    public HandlerResult handler(AnalyseModel analyseModel, HttpResult httpResult) throws Exception {
        log.info("处理生态保护红线分析服务,状态码:{}", httpResult.getCode());
        HandlerResult result = HandlerResult.createBySuccess();
        if (HttpStatus.SC_OK == httpResult.getCode()) {

            /**保存占压信息**/
            AlyResult alyResult = objectMapper.readValue(httpResult.getBody(), AlyResult.class);
            log.info("body:" + httpResult.getBody());
            if (HttpStatus.SC_OK == alyResult.getStatus()) {
                result.setData(httpResult.getBody());
            } else {
                result = HandlerResult.createByError();
                result.setMessage(String.valueOf(alyResult.getStatus()));
                result.setData(alyResult.getMessage());
                System.err.println(alyResult.getMessage());
            }
        }
        return result;

    }
}
